`
https://leetcode.cn/problems/count-subarrays-with-majority-element-ii/
`

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var countMajoritySubarrays = function (nums, target) {
  // 思路：https://leetcode.cn/problems/count-subarrays-with-majority-element-ii/solutions/3826966/mei-ju-you-wei-hu-zuo-on-zuo-fa-pythonja-ojfh/
  let n = nums.length
  const cnt = new Array(n * 2 + 1).fill(0)
  cnt[n] = 1
  let res = 0
  let s = n
  let f = 0
  for (const x of nums) {
    if (x === target) {
      f += cnt[s];
      s++
    } else {
      s--
      f -= cnt[s]
    }
    res += f
    cnt[s]++
  }
  return res
};